import { PrismaClient } from "@prisma/client";

const client = new PrismaClient();

async function main() {
  // User
  await client.user.upsert({
    where: { id: 1 },
    update: {},
    create: {
      name: "张三",
      mobile: "13211112222",
      password: "123456",
      role: "admin",
    },
  });

  await client.user.upsert({
    where: { id: 2 },
    update: {},
    create: {
      name: "李四",
      mobile: "13211112223",
      password: "123456",
      role: "normal",
    },
  });

  await client.user.upsert({
    where: { id: 3 },
    update: {},
    create: {
      name: "王五",
      mobile: "13211112224",
      password: "123456",
      role: "normal",
      isDisable: true,
    },
  });

  // Category
  await client.category.upsert({
    where: { id: 1 },
    update: {},
    create: {
      name: "红烧",
    },
  });
  await client.category.upsert({
    where: { id: 2 },
    update: {},
    create: {
      name: "小炒",
    },
  });
  await client.category.upsert({
    where: { id: 3 },
    update: {},
    create: {
      name: "时蔬",
    },
  });
  await client.category.upsert({
    where: { id: 4 },
    update: {},
    create: {
      name: "汤品",
    },
  });
  await client.category.upsert({
    where: { id: 5 },
    update: {},
    create: {
      name: "主食",
    },
  });

  // Dishes
  await client.dishes.upsert({
    where: { id: 1 },
    update: {},
    create: {
      name: "红烧肉",
      categoryId: 1,
      description: "五花肉，肥廋相兼，入口即化",
      picture:
        "/uploads/picture/57896874a59cabb1e4112706d3240d4d_9d87746d-f7a9-4273-bdbf-9d7e2c2df119.webp",
      thumbnail:
        "/uploads/thumb/thumb_57896874a59cabb1e4112706d3240d4d_9d87746d-f7a9-4273-bdbf-9d7e2c2df119.webp",
    },
  });
  await client.dishes.upsert({
    where: { id: 2 },
    update: {},
    create: {
      name: "青椒肉丝",
      categoryId: 2,
      description: "五花肉，肥廋相兼，入口即化",
      picture:
        "/uploads/picture/57896874a59cabb1e4112706d3240d4d_9d87746d-f7a9-4273-bdbf-9d7e2c2df119.webp",
      thumbnail:
        "/uploads/thumb/thumb_57896874a59cabb1e4112706d3240d4d_9d87746d-f7a9-4273-bdbf-9d7e2c2df119.webp",
    },
  });

  await client.dishes.upsert({
    where: { id: 3 },
    update: {},
    create: {
      name: "韭菜鸡蛋",
      categoryId: 2,
      description: "五花肉，肥廋相兼，入口即化",
      picture:
        "/uploads/picture/57896874a59cabb1e4112706d3240d4d_9d87746d-f7a9-4273-bdbf-9d7e2c2df119.webp",
      thumbnail:
        "/uploads/thumb/thumb_57896874a59cabb1e4112706d3240d4d_9d87746d-f7a9-4273-bdbf-9d7e2c2df119.webp",
    },
  });
}

main()
  .then(async () => {
    await client.$disconnect();
  })
  .catch(async (error) => {
    console.error(error);
    await client.$disconnect();
    process.exit(1);
  });
